package comment.until;

import java.sql.*;

public class JdbcUntil {
    public  static  final String USERNAME;
    public  static  final String URL;
    public  static  final String PASSWORD;

    static {
        USERNAME= PropertiesUntil.getValue("username");
        URL= PropertiesUntil.getValue("url");
        PASSWORD= PropertiesUntil.getValue("password");
    }

    public  static Connection getConnection() throws SQLException, ClassNotFoundException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        return DriverManager.getConnection(URL,USERNAME,PASSWORD);
    }

    public  static  void close(Connection connection, Statement statement)
    {
        try {
            if(statement!=null)
                statement.close();
            if(connection !=null)
            connection.close();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    public  static  void close(Connection connection, Statement statement, ResultSet resultSet)
    {
        try {
            if(resultSet!=null)
                resultSet.close();
            if(statement!=null)
                statement.close();
            if(connection !=null)
                connection.close();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
